package com.syni.mdd.yhd.common.all.dao.jpa.groupChat;

import com.syni.mdd.yhd.common.all.dao.BaseJPADao;
import com.syni.mdd.yhd.common.all.entity.groupChat.BmsUserChat;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Set;

public interface BmsUserChatDao extends BaseJPADao<BmsUserChat,Integer> {

    List<BmsUserChat> findByChatId(Integer chatId);

    List<BmsUserChat> findByChatIdAndRoleIdIn(Integer chatId, Set roleIds);

    List<BmsUserChat> findByChatIdAndRoleId(Integer chatId, Integer roleId,Pageable pageable);

    List<BmsUserChat> findByChatIdAndRoleId(Integer chatId, Integer roleId);

    List<BmsUserChat> findByUserIdAndRoleId(Integer userId,Integer roleId);

    List<BmsUserChat> findByUserIdAndRoleIdAndChatId(Integer userId,Integer roleId,Integer chatId);

    @Query(value = "select * from bms_user_chat where chat_id = ?1 order by field(role_id,2,3,1)",nativeQuery = true)
    List<BmsUserChat> findByGroupMember(Integer chatId,Pageable pageable);

    @Query(value = "select count(*) from bms_user_chat where chat_id = ?1",nativeQuery = true)
    Integer countGroupMember(Integer chatId);

}
